from flask import Flask

from config import DevelopmentConfig
from extensions import db
from api import api_bp
from main import main_bp
from user import user_bp


def create_app():
    app = Flask(__name__)
    app.config.from_object(DevelopmentConfig)

    db.init_app(app)

    app.register_blueprint(main_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(api_bp)

    return app


app = create_app()


@app.shell_context_processor
def shell_context():
    from models import UserActual, HouseInfoFinal  # noqa

    return {
        'db': db,
        'UserActual': UserActual,
        'HouseInfoFinal': HouseInfoFinal,
    }


if __name__ == '__main__':
    print('=== 启动模块化Flask应用 ===')
    print('应用URL: http://127.0.0.1:5000')
    print('健康检查: http://127.0.0.1:5000/health')
    print('登录页面: http://127.0.0.1:5000/login')
    print('注册页面: http://127.0.0.1:5000/register')
    print('\n按下 Ctrl+C 停止应用')
    app.run(debug=True, host='127.0.0.1', port=5000)
